package cn.myjerry.map;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * 分拣存储： 1 => N
 * 统计单词出现次数
 * 
 * 1、分割字符串
 * 2、分拣存储
 * 3、按要求查看单词出现的次数  
 * 
 * @author Jerry
 *
 */

public class MapDemo01 {
	public static void main(String[] args) {
		//1、分割字符串
		String[] arr = "Whatever is worth doing is worth doing well .".split(" ");
		//2、分拣存储
		Map<String, Integer> map = new HashMap<String, Integer>();
		for(String key:arr) {
			if(map.get(key) == null) {
				map.put(key, 1);
			} else {
				map.put(key, map.get(key) + 1);
			}
		}
		Set<String> set = map.keySet();
		Iterator<String> iter = set.iterator();
		while(iter.hasNext()) {
			String key = iter.next();
			Integer value = map.get(key);
			System.out.println(key +"==>"+ value);
		}
	}
}
